package com.example.springboot.Controler;

import com.example.springboot.Service.impl.UserServiceimpl;
import com.example.springboot.config.Result;
import com.example.springboot.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserServiceimpl userServiceimpl;
    @PostMapping("/save")
    public Result Save(@RequestParam String name,@RequestParam String sex,@RequestParam int age,@RequestParam String id) {
        User user = new User(id,name,sex,age,"123");
        userServiceimpl.Save(user);
        return Result.success();
    }
    @GetMapping("/getAll")
    public Result getAll()
    {
        ArrayList<User> users =userServiceimpl.getAll();
        return Result.success(users);
    }
    @GetMapping("/delete")
    public Result Delete(@RequestParam String id){
        userServiceimpl.DeleteById(Integer.parseInt(id));
        return Result.success();
    }
    @PostMapping("/login")
    public Boolean login(@RequestParam String id,@RequestParam String password){
        return userServiceimpl.login(id,password);
    }
}
